﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.Security;
using System.Text;

public partial class admin_ChangePassword : SitePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        InitData();
    }
    private void InitData()
    {
        string validateGroup = "pass";
        vsumPass.ValidationGroup = btnSave.ValidationGroup = reqNewPass.ValidationGroup = cmpConfirmNewPass.ValidationGroup = reqOld.ValidationGroup = reqConfirmNewPass.ValidationGroup = validateGroup;
        //Init message
        reqNewPass.ErrorMessage = string.Format(Resources.Resource.MSG_REQUIREMENT, "New pass");
        reqOld.ErrorMessage = string.Format(Resources.Resource.MSG_REQUIREMENT, "Old pass");
        reqConfirmNewPass.ErrorMessage = string.Format(Resources.Resource.MSG_REQUIREMENT, "Confirm new pass");
        cmpConfirmNewPass.ErrorMessage = string.Format(Resources.Resource.MSG_COMPARE, "Confirm new pass", "New pass");

    }


    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {

            MembershipUser user = Membership.GetUser(this.userloginId);
            if (Membership.ValidateUser(user.UserName, txtOldPass.Text.Trim()))
            {
                if (user.ChangePassword(user.ResetPassword(), txtNewPass.Text.Trim()))
                {
                    lblErrorMessage.Text = Resources.Resource.MSG_CHANGEPASS_SUCCESSFULL;
                    txtNewPass.Text = string.Empty;
                    txtConfirmNewPass.Text = string.Empty;
                    txtOldPass.Text = string.Empty;
                    return;
                }
                else lblErrorMessage.Text = Resources.Resource.MSG_UPDATE_ERROR;
            }
            else lblErrorMessage.Text = string.Format(Resources.Resource.MSG_VALID, "Old password");

        }
    }
}